﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class SharedPool : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString.HasKeys())
        {
            if (Request.QueryString["listid"] != String.Empty)
                Session["listid"] = Request.QueryString["listid"];
            else
                Session["listid"] = 1;


            if (Request.QueryString["dnis"] != null)
            {
                Session["dnis"] = Request.QueryString["dnis"];
            }
            else
            {
                Session["dnis"] = "9999999999";
            }

            Session["servername"] = Request.QueryString["servername"];
            Session["projectname"] = Request.QueryString["projectname"];
            Session["campaignname"] = Request.QueryString["campaignname"];
            Session["agentid"] = Request.QueryString["agentid"];
            Session["agentfirst"] = Request.QueryString["agentfirst"];
            Session["agentlast"] = Request.QueryString["agentlast"];

            //ValidateIBListID();
        }
    }

    //public void ValidateIBListID()
    //{
    //    string connString = "user id=portalUser;data source=" + Session["Servername"] + ";initial catalog=VoiceNet_" + Session["ProjectName"] + ";password=sqluser";
    //    SqlConnection conn = new SqlConnection(connString);

    //    conn.ConnectionString = connString;
    //    conn.Open();
    //    System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand();
    //    string lccommand = null;

    //    lccommand = "select top 1 case when enterpriselistid = " + Session["listid"] + " then calldataid else 0 end as calldataid " +
    //                "from _calldata nolock order by case when enterpriselistid = " + Session["listid"] + " then calldataid else 0 end desc";

    //    command.CommandType = CommandType.Text;
    //    command.CommandText = lccommand;
    //    command.Connection = conn;
    //    SqlDataReader dr = default(SqlDataReader);
    //    dr = command.ExecuteReader(CommandBehavior.SingleRow);
    //    if (dr.HasRows)
    //    {
    //        dr.Read();
    //        if (dr["calldataid"] != "0")
    //        {
    //            Session["CallDataID"] = dr["CallDataID"].ToString();
    //        }
    //        else //if no calldata row exists for current enterpriselistid, create one
    //        {
    //            lccommand = "insert into CallData (enterpriselistid, lastupdate, btn) " +
    //                        "values (@listid, getdate(), @btn) set @calldataid = SCOPE_IDENTITY()";



    //            SqlParameter callDataIDKey = new SqlParameter("@calldataid", SqlDbType.Int);
    //            callDataIDKey.Direction = ParameterDirection.Output;


    //            using (SqlConnection connection = new SqlConnection(connString))
    //            {
    //                SqlCommand cmd = new SqlCommand(lccommand, connection);

    //                cmd.Parameters.Add(callDataIDKey);

    //                cmd.Parameters.Add("@listid", SqlDbType.Int);
    //                cmd.Parameters.Add("@btn", SqlDbType.VarChar);


    //                cmd.Parameters["@listid"].Value = Session["listid"];
    //                cmd.Parameters["@btn"].Value = Session["btn"];


    //                cmd.Connection.Open();
    //                cmd.ExecuteNonQuery();
    //            }

    //            Session["CallDataID"] = (int)callDataIDKey.Value;
    //        }

    //        dr.Close();
    //        dr = null;
    //        conn.Close();
    //    }
    //    else
    //    {
    //        dr.Close();
    //        dr = null;
    //        conn.Close();
    //    }
    //    dr = null;
    //}
}
